package com.sky.service.impl;

import com.sky.dto.DishDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.mapper.DishFlavorMapper;
import com.sky.service.DishFlavorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class DishFlavorServiceImpl implements DishFlavorService {
    @Resource
    private DishFlavorMapper DishFlavorMapper;

    @Override
    public void insertDishFlavor(DishDTO dishDTO, Dish dish) {
        List<DishFlavor> flavors = dishDTO.getFlavors();
        if (flavors != null && !flavors.isEmpty()) {
            for (DishFlavor flavor : flavors) {
                if (!flavor.getName().isEmpty() && !flavor.getValue().isEmpty()) {
                    flavor.setDishId(dish.getId());
                    DishFlavorMapper.insert(flavor);
                }
            }
        }
    }
}
